package com.shyroke.calculation;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * 计算应急方案的折中评价值Qi
 * 
 * @author shyroke
 *
 */
public class QiCal {

	public  double NANTA = 0.5;

	public double S_plus; // s+
	public double S_reduce; // s-
	public double S_result; // s-减s+

	public double R_plus; // R+
	public double R_reduce; // R-
	public double R_result; // R-减R+

	Map<String, Double> siMap;
	Map<String, Double> RiMap;
	
	public QiCal(Map<String, Double> siMap, Map<String, Double> RiMap) {
		this.siMap = siMap;
		this.RiMap = RiMap;
		for (int i = 1; i <= siMap.size(); i++) {

			double si = siMap.get("x" + i);
			if (i == 1) {
				this.S_plus = si;
			}

			this.S_plus = S_plus < si ? S_plus : si;
			this.S_reduce = S_reduce > si ? S_reduce : si;
		}

		for (int i = 1; i <= RiMap.size(); i++) {
			double ri = RiMap.get("x" + i);
			if (i == 1) {
				this.R_plus = ri;
			}

			this.R_plus = R_plus < ri ? R_plus : RiMap.get("x" + i);
			this.R_reduce = R_reduce > ri ? R_reduce : ri;
		}

		this.S_result = this.S_reduce - this.S_plus;
		this.R_result = this.R_reduce - this.R_plus;

	}

	/**
	 *  
	 * @return key表示决策方案，value表示Qi
	 */
	public Map<String,Double> getQi(){
		Map<String,Double> resultMap = new HashMap<>();
		
		for(int i=1;i<=siMap.size();i++) {
			double Si = siMap.get("x"+i);  //第i个方案的Si值
			double Ri = RiMap.get("x"+i);  //第i个方案的Ri值
			double Si_reduce_Splus = Si - this.S_plus;  //Si-S+
			double Ri_reduce_Rplus = Ri - this.R_plus;  //Si-S+
			double left = this.NANTA * (Si_reduce_Splus / this.S_result );
			double right = this.NANTA * (Ri_reduce_Rplus / this.R_result );
		 
			resultMap.put("x"+i,Double.valueOf(new DecimalFormat("#.000").format(left+right)));
		}
		
		return resultMap;
	}
	
	
}
